<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
    <head>
        <th:block th:include="include :: header('修改知识库类别')"/>
        <th:block th:include="include :: summernote-css" />
        <link rel="stylesheet" type="text/css" th:href="@{/ajax/libs/qxEasyUI/themes/default/easyui.css}">
    </head>
    <style>
        .combo{
            border: 1px solid #e5e6e7;
            border-radius: 5px;
        }
    </style>
    <body style="background-color: #F4F6FA">
        <div class="main-content" style="margin: 5px;padding: 0">
            <form class="form-horizontal" style="background-color: #F4F6FA" id="form-kbmPoint-edit" th:object="${point}">
                <input type="hidden" name="pkid" th:field="*{pkid}"/>
                <div class="col-sm-12" style="display: flex;justify-content: center">
                    <div class="col-sm-10 entering-page">
                        <div class="col-sm-12" style="margin-top:10px;">
                            <div class="form-group col-sm-12">
                                <label class="col-sm-2 control-label is-required">问题标题：</label>
                                <div class="col-sm-10">
                                    <input class="form-control" type="text" name="kldgquestion" id="kldgquestion" th:field="*{kldgquestion}" required>
                                </div>
                            </div>
                            <div class="form-group col-sm-12">
                                <div class="col-sm-6" style="margin: 0 0 0 -5px;">
                                    <label class="col-sm-4 control-label is-required">问题类型：</label>
                                    <div class="col-sm-8">
                                        <select name="sortbc" onchange="questionCate(this)"
                                                style="border: 1px solid #e5e6e7;width: 265px;height: 31px;border-radius: 4px;">
                                            <option th:each="cate : ${qCate}" th:text="${cate.text}"
                                                    th:value="${cate.id}" th:selected="${cate.id} eq *{sortbc}"></option>
                                        </select>
                                        <input id="qCateName" name="sortbn" type="hidden" th:field="*{sortbn}"/>
                                    </div>
                                </div>
                                <div class="col-sm-6">
                                    <div th:if="${point.sortac != ''}">
                                        <label class="col-sm-4 control-label is-required">内容类型：</label>
                                        <div class="col-xs-8">
                                            <input id="contentCate" th:value="*{sortan}"
                                                   style="width:268px;height:31px;border-radius: 4px;">
                                            <input id="sortac" name="sortac" type="hidden" th:field="*{sortac}"/>
                                            <input id="sortan" name="sortan" type="hidden" th:field="*{sortan}"/>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group col-sm-12">
                                <label class="col-sm-2 control-label">问题答案：</label>
                                <div class="col-sm-10">
                                    <div class="ibox float-e-margins">
                                        <div class="ibox-content no-padding">
                                                <textarea name="kldganswer" th:field="*{kldganswer}" class="summernote">
                                                </textarea>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group col-sm-12">
                                <label class="col-sm-2 control-label">参考依据：</label>
                                <div class="col-sm-10">
                                    <div class="ibox float-e-margins">
                                        <div class="ibox-content no-padding">
                                                <textarea name="relationx" class="summernote2" th:field="*{relationx}">
                                                </textarea>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group col-sm-12">
                                <div class="col-sm-6">
                                    <label class="col-sm-4 control-label">是否公开：</label>
                                    <div class="col-sm-8">
                                        <select id="openflag" name="openflag" class="form-control m-b" style="width: 265px;margin: 0 0 0 -5px;">
                                            <option value="0" th:selected="${point.openflag} eq 0">否</option>
                                            <option value="1" th:selected="${point.openflag} eq 1">是</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="col-sm-6">
                                    <label class="col-sm-4 control-label is-required">有效时间：</label>
                                    <div class="col-sm-8">
                                        <input name="limittime" id="limittime" class="form-control" type="text" style="width: 265px;" th:field="*{limittime}"/>
                                        <div class="input-group-append " style="position: absolute;top: 10px;right: 30px;">
                                            <span class="glyphicon glyphicon-calendar "></span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-2">
                            <!--按钮-->
                            <div class="col-sm-12 entering-bt" style="margin-top: 10px;position:fixed;">
                                <button type="button" class="btn btn-sm btn-info" onclick="submitHandler()">保存
                                </button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <button type="button" class="btn btn-sm btn-warning" onclick="closeItem()">关闭
                                </button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            </div>
                    </div>
                </div>
            </form>
        </div>
        <script th:src="@{/ajax/libs/layui/laydate.js}"></script>
        <th:block th:include="include :: footer"/>
        <th:block th:include="include :: summernote-js"/>
        <script th:src="@{/ajax/libs/qxEasyUI/jquery.easyui.min.js}"></script>
        <script>
            var prefix = ctx + "system/kbm/point";

            // 时间
            laydate.render({
                elem: '#limittime',
                type: 'datetime',
                trigger: 'click'
            });

            $('#contentCate').combotree({
                url: '/system/kbm/category/kbmContentCate',
                required: false,
                onSelect: function (record) {
                    $("#sortac").val(record.id);
                    $("#sortan").val(record.text);
                    $('.combo-text').removeClass('error');
                }
            });

            $("#form-kbmPoint-edit").validate({
                onkeyup: false,
                rules: {
                    kldgquestion: {
                        required: true
                    },
                    kldganswer: {
                        minlength: 10
                    },
                    relationx:{
                        required: false
                    }
                },
                focusCleanup: true
            });

            function submitHandler() {
                var flag = $.validate.form();
                if($("#contentCate").val() == '') {
                    $('.combo-text').addClass('error');
                    flag = false;
                }
                else {
                    $('.combo-text').removeClass('error');
                }
                if (flag) {
                    $.operate.save(prefix + "/kbmPointEdit", $('#form-kbmPoint-edit').serialize());
                }
            }

            function doSubmit(index, layero) {
                layer.close(index);
            }

            function questionCate(event){
                $('#qCateName').val(event.options[event.selectedIndex].text)
            }

            // 富文本
            $(document).ready(function () {
                $('.summernote').summernote({
                    lang: 'zh-CN',
                    tabsize: 2,
                    height: 150, //高度
                    followingToolbar: false,
                    callbacks: {
                        onKeydown: function (e) {
                            e.stopPropagation();
                        },
                        onImageUpload: function (files) {
                            sendFile(files[0], this);
                        }
                    }
                });

                $('.summernote2').summernote({
                    lang: 'zh-CN',
                    tabsize: 2,
                    height: 150, //高度
                    followingToolbar: false,
                    callbacks: {
                        onKeydown: function (e) {
                            e.stopPropagation();
                        },
                        onImageUpload: function (files) {
                            sendFile(files[0], this);
                        }
                    }
                });
            });

            //图片上传
            function sendFile(file, obj) {
                var data = new FormData();
                data.append("file", file);
                $.ajax({
                    type: "POST",
                    url: ctx + "common/upload",
                    data: data,
                    cache: false,
                    contentType: false,
                    processData: false,
                    dataType: 'json',
                    success: function(result) {
                        if (result.code == web_status.SUCCESS) {
                            $(obj).summernote('editor.insertImage', result.url, result.fileName);
                        } else {
                            $.modal.alertError(result.msg);
                        }
                    },
                    error: function(error) {
                        $.modal.alertWarning("图片上传失败。");
                    }
                });
            }
        </script>
    </body>
</html>
